package com.qqbot.service.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qqbot.enums.StatusEnum;
import com.qqbot.exception.BusinessException;
import com.qqbot.model.user.User;
import com.qqbot.dao.user.UserDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qqbot.utils.Constant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author fyq
 * @since 2023-03-02
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Override
    public boolean isItMaster(String bot, String qq, String groupNo) throws BusinessException {
        if (StringUtils.isAnyBlank(bot, qq, groupNo)) {
            throw new BusinessException(Constant.PARAMS_IS_NULL_MESSAGE);
        }
        return this.baseMapper.countMasterQq(bot, qq, groupNo) > 0;
    }

    @Override
    public boolean isItMaster(String bot, String qq) throws BusinessException {
        if (StringUtils.isAnyBlank(bot, qq)) {
            throw new BusinessException(Constant.PARAMS_IS_NULL_MESSAGE);
        }
        QueryWrapper<User> query = new QueryWrapper<>();
        query.eq("bot", bot);
        query.eq("qq", qq);
        query.eq("master", StatusEnum.TRUE.getCode());
        return this.count(query) > 0;
    }
}
